package games.gong.durid.service.impl;

import games.gong.durid.entity.RolePermission;
import games.gong.durid.mapper.RolePermissionMapper;
import games.gong.durid.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RolePermissionServiceImpl implements RolePermissionService {
    
    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    
    @Override
    public int addRolePermission(RolePermission rolePermission) {
        rolePermission.setCreateTime(LocalDateTime.now());
        return rolePermissionMapper.insert(rolePermission);
    }
    
    @Override
    public int deleteRolePermission(Long id) {
        return rolePermissionMapper.deleteById(id);
    }
    
    @Override
    public int deleteRolePermissionByRoleIdAndPermissionId(Long roleId, Long permissionId) {
        return rolePermissionMapper.deleteByRoleIdAndPermissionId(roleId, permissionId);
    }
    
    @Override
    public RolePermission getRolePermissionById(Long id) {
        return rolePermissionMapper.selectById(id);
    }
    
    @Override
    public List<RolePermission> getRolePermissionsByRoleId(Long roleId) {
        return rolePermissionMapper.selectByRoleId(roleId);
    }
    
    @Override
    public List<RolePermission> getRolePermissionsByPermissionId(Long permissionId) {
        return rolePermissionMapper.selectByPermissionId(permissionId);
    }
}